﻿using System.Collections.Generic;
using System.Linq;
using SportMeetingPlanner.Models;

namespace SportMeetingPlanner.ViewModels
{
    public class SubscriptionsViewModel
    {
        public IList<Subscription> Subscriptions { get; set; }
        public Meeting Meeting { get; set; }
        public bool IsCrtUserSubscribed;

        public SubscriptionsViewModel(Meeting meeting, IList<Subscription> subscriptions, string userName)
        {
            Meeting = meeting;
            Subscriptions = subscriptions;
            IsCrtUserSubscribed = IsSubscribed(userName);
        }

        /// <summary>
        /// C'tor
        /// </summary>
        public SubscriptionsViewModel()
        {
        }

        private bool IsSubscribed(string username)

        {
            var subscriptions = Subscriptions.Where(s => s.MeetingId == Meeting.MeetingId && s.UserName == username);
            return subscriptions.Count() > 0 ? true: false;
        }
    }
}
